<template>
  <div>
    <van-nav-bar :title="keyword + ' 的搜索内容'" fixed left-arrow @click-left="$router.back()"/>

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
  <van-cell v-for="(item, index) in list" :key="index" :title="item.title" @click="$router.push('/article/' + item.art_id)" />
</van-list>
  </div>
</template>

<script>
import { getSearch } from '@/api/search'
export default {
  name: 'SearchResult',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1 // 页码
    }
  },
  methods: {
    async onLoad() {
      const res = await getSearch(this.page)
      console.log(res.data.results)

      this.list = [...this.list, ...res.data.results]

      this.loading = false
      this.page++

      if (res.data.results.length === 0) this.finished = true
    }
  },
  computed: {
    keyword() {
      return this.$route.query.keyword
    }
  }
}
</script>

<style lang="less" scoped>
.van-list {
  padding-top: 46px;
}
</style>
